<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <link rel="stylesheet" th:href="@{/static/js/common/jquery.min.js}" />
    <link rel="stylesheet" th:href="@{/static/js/common/jquery-1.10.2.js}" />
    <link rel="stylesheet" th:href="@{/static/js/common/jquery.md5.js}" />
    <link rel="stylesheet" th:href="@{/static/js/common/jquery.cookie.js}" />
    <!--<link rel="icon" href="../static/img/logoicon.png" th:href="@{/img/logoicon.png}" type="image/x-icon"/>
    <link rel="stylesheet" href="../static/css/login.css" th:href="@{/css/login.css}"/>-->

    <link rel="stylesheet" th:href="@{/static/css/login.css}" />
    <link rel="stylesheet" th:href="@{/static/img/logoicon.png}"/>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录</title>
    <meta name="keywords" content="统一管理平台">
    <meta name="description" content="统一管理平台">
</head>
<body>
<div class="login-page">
    <div class="login-content">
        <div class="login-tit">云平台</div>
        <div class="login-input">
            <input type="text" value="" placeholder="用户名/手机号" id="loginName" onkeydown="KeyDown();">
        </div>
        <div class="login-input">
            <input type="password" value="" placeholder="密码" id="password" onkeydown="KeyDown();" autocomplete="new-password">
        </div>
        <div class="login-btn">
            <div class="login-btn-left">
                <span id="loginBtn" onclick="login(2)">登录</span>
            </div>
            <!--<div class="login-btn-right" onClick="changeImg()">
                <img src="../img/check.png" alt="" id="remember" class=""> 记住密码
            </div>-->
        </div>
    </div>
</div>
<!--弹出提示框end-->
<div id="showTip" class="hide">
    <span></span>
</div>
<!--<script src="../static/js/common/jquery-1.10.2.js" th:src="@{/js/common/jquery-1.10.2.js}"></script>
<script src="../static/js/common/jquery.md5.js" th:src="@{/js/common/jquery.md5.js}"></script>
<script src="../static/js/common/jquery.cookie.js" th:src="@{/js/common/jquery.cookie.js}"></script>-->


<script type="text/javascript">
    /*$(document).ready(function () {
        if (window != top) {
            window.top.location.href="../login.html";
        }

        var storage=window.localStorage;
        storage.removeItem("history");
        storage.setItem("loginName","adminLogin.html");

        var rem = $.cookie('remember');
        if(rem){
            var pic = document.getElementById('remember');
            pic.src ="img/checked.png";
            $("#loginName").val($.cookie("loginName"));
            $("#password").val($.cookie("password"));
        }
    });
    function changeImg(){
        var pic = document.getElementById('remember');
        // console.log(pic.src)
        if(pic.getAttribute("src",2) =="img/check.png"){
            pic.src ="img/checked.png";
        }else{
            pic.src ="img/check.png";
        }
    }*/

    var  loginNameTxt="";
    function KeyDown()
    {
        if (event.keyCode == 13)
        {
            login(2);
        }
    }
    //注册正则 简单判断
    /*$('#loginBtn').click(function(){
        login(2);
    })*/

    function login(type){
        // save_cookies();
        if(type==2){
            // var user = $.trim($("#loginName").val());$("#loginName").val();
            // var password = $.trim($("#password").val());
            var user = $("#loginName").val();
            var password = $("#password").val();
            //只能输入2-16个以字母开头、可带数字、“_”、“.”的字串
            // var userPattern = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){1,15}$/;
            //密码(以字母开头，长度在2~18之间，只能包含字母、数字和下划线)
            var pwdPattern = /^[a-zA-Z]\w{1,15}$/;
            if(user == '' || user == 'undefined'){
                $('#showTip span').html('手机号不能为空');
                $("#showTip").removeClass("hide");
                setTimeout(function () {
                    $("#showTip").addClass("hide");
                },700);
                return;
            }else if(user.length>11){
                $('#showTip span').html('手机号或密码输入错误');
                $("#showTip").removeClass("hide");
                setTimeout(function () {
                    $("#showTip").addClass("hide");
                },700);
                return;
            }

            if(password == '' || password == 'undefined'){
                $('#showTip span').html('密码不能为空');
                $("#showTip").removeClass("hide");
                setTimeout(function () {
                    $("#showTip").addClass("hide");
                },700);
                return;
            }else if(!pwdPattern.test(password)){
                $('#showTip span').html('手机号或密码输入错误');
                $("#showTip").removeClass("hide");
                setTimeout(function () {
                    $("#showTip").addClass("hide");
                },1000);
                return;
            }

            var mdPassword=$.md5(password);
            var randomStr = "";//容器
            for(var i =0;i<5;i++){
                randomStr+=Math.floor(Math.random()*10);
            }
            password=mdPassword.slice(0, 1) + randomStr + mdPassword.slice(1);
            var valueStr='{"loginName":"'+user+'","password":"'+password+'"}';
            $.ajax({
                url: "/loginInfo/LoginReq?rnd=" + Math.random(),
                type: 'post',
                dataType: "json",
                contentType: 'application/json;charset=UTF-8',
                data: valueStr,
                // 存储区域数据
                success: function (data) {
                    // alert("成功了")
                    if (data.flag == 0){
                        //在原有窗口打开
                        window.location.href = "../webSocket";
                    } else {
                        alert(data.msg);
                    }

                },
                error: function (data) {
                    console.log(data.msg);
                }
            });

        }
    }

    //保存到cookie
    function save_cookies(){
        // var pic = document.getElementById('remember');
        // $.cookie("remember","true",{expires:7});
        $.cookie("loginName",loginName,{expires:7 });
        $.cookie("password",password,{expires:7 });
        /*if(pic.getAttribute("src",2) =="img/check.png"){
            $.cookie("remember","false",{expires:-1});
            $.cookie("loginName","",{ expires:-1 });
            $.cookie("password","",{ expires:-1 });
        }else{
            var loginName = $("#loginName").val();
            var password = $("#password").val();

            $.cookie("remember","true",{expires:7});
            $.cookie("loginName",loginName,{expires:7 });
            $.cookie("password",password,{expires:7 });
        }*/
    };
</script>

</body>

</html>